#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=4e6+1;
int n,k,m,x,c,ans=2e9,b[N];
pair<int,int> a[N];
int main()
{
	freopen("contest.in","r",stdin);
	freopen("contest.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>k;
		for(int j=1;j<=k;j++)
		{
			cin>>x;
			a[++m]={x,i};
		}
	}
	sort(a+1,a+m+1);
	for(int i=1,j=1;i<=m;i++)
	{
		if(!b[a[i].se])	c++;
		b[a[i].se]++;
		if(c==n)
		{
			while(b[a[j].se]>1)
			{
				b[a[j].se]--;
				j++;
			}
			ans=min(ans,a[i].fi-a[j].fi);
		}
	}
	cout<<ans;
	return 0;
}
